<html>
<script>

function factorial(n){
  if(n ===1){
     return 1;
  }
  return n * factorial(n-1);
}

function tailFactorial(n, total) {
  if(n ===1)
    return total;
  return tailFactorial(n -1, n * total);
}

function factorial2(n) {
  return tailFactorial(n,1);
}

var N = 10;
alert(factorial(N));
alert(factorial2(N)); 

</script>
</html>
